home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-11 | 4.6 KB | 197 lines | [TEXT/R*ch] |
- /*
-
- Listing 1: Demo.java
-
- Demo.java
- Define and create a new instance of our applet.
-
- */
-
- // Import the generic Java classes.
- import java.applet.*;
- import java.awt.*;
- import java.io.*;
- import java.lang.*;
-
- // Our applet class definition.
- public class Demo extends java.applet.Applet
- {
- // Instances of classes we need.
- ToolPalette theToolPalette;
- public Demo myDemo;
- BackdropCanvas theBackdropCanvas;
- NewButtonFrame theNewButtonFrame;
-
- // Our first method.
- public void init()
- {
- // Variables local to this method, used only to setup our applet.
- int tempX = 320, tempY = 100;
- int tempWidth = 300, tempHeight = 300;
- int theColor;
- Color menuColor[] = { Color.black, Color.green,
- Color.pink, Color.blue,
- Color.lightGray, Color.red,
- Color.cyan, Color.magenta,
- Color.white, Color.darkGray,
- Color.orange, Color.yellow,
- Color.gray };
-
- // Setup our applet display area.
- setBackground( Color.gray );
- setForeground( Color.black );
- setLayout( new BorderLayout() );
-
- // We will want to refer to our applet later.
- myDemo = this;
-
- // Create an instance of our drawing canvas.
- theBackdropCanvas = new BackdropCanvas();
-
- // Now that our graphics canvas is ready, add it to the center of our applet.
- add( "Center", theBackdropCanvas );
-
- // Our tool palette.
- theToolPalette = new ToolPalette( myDemo );
-
- // A "dialog" to solicit input from the user.
- theNewButtonFrame = new NewButtonFrame( myDemo );
-
- // Retrieve some default color information from our tool palette.
- theColor = theToolPalette.doGetColor( 0 );
-
- // Call a method within our graphics canvas and tell it to set the background color.
- theBackdropCanvas.doSetBackgroundColor(
- menuColor[ theColor ] );
-
- // Our applet should draw everything it knows about the first time through.
- repaint();
- }
-
- // Haven't made use of this yet.
- public void start()
- {
- }
-
- // Stop loading/running when requested.
- public void stop()
- {
- myDemo.doDestroy();
- System.exit( 0 );
- }
-
- // Graceful exit when requested.
- public void doDestroy()
- {
- theToolPalette.hide();
- theBackdropCanvas.hide();
- theNewButtonFrame.hide();
- System.exit( 0 );
- }
-
- // Create a panel/rectangle object upon request from the tool palette.
- public boolean doAddRect()
- {
- boolean doRepaint = false;
- int theColor;
- String theNewString = new String( "" );
-
- theColor = theToolPalette.doGetColor( 1 );
- theBackdropCanvas.doChangeColor( 1, theColor );
-
- theColor = theToolPalette.doGetColor( 2 );
- theBackdropCanvas.doChangeColor( 2, theColor );
-
- doRepaint = theBackdropCanvas.doAddDecafObject( 0,
- theNewString );
-
- if ( doRepaint )
- theBackdropCanvas.repaint();
-
- return true;
- }
-
- // Setup our dialog that will request a button label from the user.
- public boolean doCreateButtonFrame()
- {
- boolean doRepaint = false;
- boolean dummy = false;
-
- dummy = theNewButtonFrame.doSetupDefaults();
- theNewButtonFrame.show();
-
- if ( doRepaint )
- repaint();
-
- return true;
- }
-
- // Add a "button" object upon request from the tool palette.
- public boolean doAddButton( String theNewString )
- {
- boolean doRepaint = false;
- int theColor;
-
- theColor = theToolPalette.doGetColor( 3 );
- theBackdropCanvas.doChangeColor( 3, theColor );
-
- theColor = theToolPalette.doGetColor( 4 );
- theBackdropCanvas.doChangeColor( 4, theColor );
-
- doRepaint = theBackdropCanvas.doAddDecafObject( 1,
- theNewString );
-
- if ( doRepaint )
- theBackdropCanvas.repaint();
-
- return true;
- }
-
- // Change the color for one or more of our objects upon request from the tool palette.
- public boolean doChangeColor( int theItem, int theColor )
- {
- boolean doRepaint = false;
-
- doRepaint = theBackdropCanvas.doChangeColor( theItem,
- theColor );
-
- if ( doRepaint )
- theBackdropCanvas.repaint();
-
- return true;
- }
-
- // Delete one selected item upon request from the tool palette.
- public boolean doDeleteItem()
- {
- boolean doRepaint = false;
-
- doRepaint = theBackdropCanvas.doDeleteDecafObject();
-
- if ( doRepaint )
- theBackdropCanvas.repaint();
-
- return true;
- }
-
- // Change the background color for our drawing area on request from the tool palette.
- public boolean doSetBackColor( int theColor )
- {
- Color menuColor[] = { Color.black, Color.green,
- Color.pink, Color.blue,
- Color.lightGray, Color.red,
- Color.cyan, Color.magenta,
- Color.white, Color.darkGray,
- Color.orange, Color.yellow,
- Color.gray };
-
- theBackdropCanvas.doSetBackgroundColor( menuColor[
- theColor ] );
-
- theBackdropCanvas.repaint();
-
- return true;
- }
-
- }
-